﻿namespace BasicSkin
{
    using System;
    using System.Diagnostics;
    using System.Reflection;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;

    using ElisVK;

    public class WindowUI : IWindowUI
    {
        #region Fields

        private ResourceDictionary _styles;

        #endregion Fields

        public ResourceDictionary Styles
        {
            get
            {
                if (_styles == null)
                {
                    var uri = new Uri(@"/BasicSkin;component/Themes\Generic.xaml", UriKind.RelativeOrAbsolute);

                    _styles = new ResourceDictionary { Source = uri };
                }

                return _styles;
            }
        }

        public ImageSource GetImage(string name)
        {
            var uri = new Uri("/BasicSkin;component/Res/" + name, UriKind.RelativeOrAbsolute);

            return new BitmapImage(uri);
        }

        public string GetString(string key)
        {
            return Properties.Resources.ResourceManager.GetString(key);
        }

        public UserControl GetUserControl(string userControl)
        {
            var assembly = Assembly.GetExecutingAssembly();

            return (UserControl ) assembly.CreateInstance(string.Format("{0}.{1}", assembly.GetName().Name, userControl));
        }
    }
}
